package com.cgbl.cg.adapter

import android.os.Bundle
import androidx.appcompat.widget.AppCompatImageView
import com.cgbl.cg.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.configs.AppConstants
import com.robot.base.model.PreferentPageBean
import com.robot.base.util.arouter.ARouterUtil
import com.robot.base.utils.pic.ImageLoaderUtils

class LimitedTimeAdapter(val visit: Boolean = true, val titleVisit: Boolean = true) :
    BaseQuickAdapter<PreferentPageBean, BaseViewHolder>(R.layout.app_item_more_course) {
    override fun convert(holder: BaseViewHolder, item: PreferentPageBean) {
        if (!visit) {
            holder.setGone(R.id.item_tv_3, true)
        }
        if (!titleVisit) {
            holder.setGone(R.id.item_iv_heat, true)
                .setGone(R.id.item_tv_1, true)
        }

        holder.setText(
            R.id.item_tv_1,
            "${item.projectBuy?:""}人在学·${item.studyTime ?: 0}小时"
        )
            .setText(R.id.item_tv_name, item.projectName)
            .setText(R.id.item_tv_label, item.projectKey)
            .setText(R.id.item_tv_3, "￥${item.preferentPriceInfo ?: "0.00"}")
            .setText(R.id.item_tv_2, "￥${item.preferentPrice ?: "0.00"}")

//        if (item.free == "2") {
//            holder.setGone(R.id.item_tv_3, true)
//            SpanUtils.with(holder.getView(R.id.item_tv_2)).append("VIP限免")
//                .setForegroundColor(ColorUtils.getColor(R.color.app_color_ffc063)).create()
//        } else {
//            holder.setGone(R.id.item_tv_3, false)
//            SpanUtils.with(holder.getView(R.id.item_tv_2)).append("￥${item.coursePrice ?: "0.00"}")
//                .setForegroundColor(ColorUtils.getColor(R.color.app_color_cc2d2d)).create()
//        }

        holder.itemView.setOnClickListener {
            if (item.projectType == "1") {
                ARouterUtil.goToActivityWithBundle(AppConstants.Router.Mine.A_MINE_RESOURCE_PROFILE,
                    Bundle().apply {
                        putString(AppConstants.BundleKey.ID, item.projectId)
                    })
            } else {
                ARouterUtil.goToActivityWithBundle(AppConstants.Router.Mine.A_MINE_COURSE_PROFILE,
                    Bundle().apply {
                        putString(AppConstants.BundleKey.ID, item.projectId)
                    })
            }
        }

        val ivImg = holder.getView<AppCompatImageView>(R.id.item_iv_img)
        ImageLoaderUtils.displayRound(context, ivImg, item.projectCover, 10)
    }
}